/**
 * add record to a domain
 */
export default defineEventHandler(async (event) => {
  const name = getRouterParam(event, 'name')
  const uuid = getRouterParam(event, 'uuid')
  const data = await useStorage().getItem<Domain>(`first:domain:${name}`)
  if (data === null) {
    // TODO: error handle.
    return 'emm'
  }
  const body = await readBody<RRecord>(event)
  const records = data.records || []
  const toBeUpdate = records.findIndex((r) => r.uuid === uuid)
  if (toBeUpdate === -1) {
    return '404'
  }
  records[toBeUpdate] = body
  data.records = records
  await useStorage().setItem(`first:domain:${name}`, data)
  return 'success'
})
